/* $Header: as_cmds.c,v 2.2 01/10/02 10:29:10 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1994                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: as_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  John DeGood                                                */
/*                                                                     */
/* MODULE PURPOSE: This module will handle the ALS commands.           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <error.h>
#include <mio.h>
#include <cmd_set.h>
#include <cmdproc.h>
#include <method.h>
#include <hostutil.h>
#include <cmd_tbls.h>
#include <sampler.h>
#include <als.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/

/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/

/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

/*****************************/
/*   STATIC VARIABLES        */
/*****************************/

/*****************************/
/*   MACROS                  */
/*****************************/

/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/



/***********************************************************************/
/* FUNCTION: DoASEO                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Echo command.                                              */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoASEO(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
U_INT16 len;

   len = 0;

   if (p_cmd->parmv[0] == 1)
   {
      len = PutAsciiParam((BIT8 *)"\"", p_resp_parm);
      len += PutAsciiParam((BIT8 *)&(p_cmd->parms[p_cmd->parmv[1]]),
                                     p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)"\"", p_resp_parm+len);
      return len;
   }
   else
   {
      CmdErrorHandler(p_cmd,1,INVALID_PARAM);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoASEO                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoASTW - load/store ALS tower workfile                    */
/* ========                                                            */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* PARAMETERS: *p_cmd, *p_resp_parm - command system pointers          */
/*                                                                     */
/***********************************************************************/

INT16 DoASTW( CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   UI_ERR error;

   error = OK;

   /* this command requires at least 1 parameter */
   if (p_cmd->parmv[0] == 0)
   {
      CmdErrorHandler(p_cmd, 0, NUM_OF_PARAM);
      return NO_RESPONSE;
   }

   /* if '?' return tower setpts */
   if (p_cmd->parms[p_cmd->parmv[1]] == '?')
   {
      return AddTowerSetpts (FRONT, p_resp_parm);
   }
   else
   /* load tower setpts     */
   {
      error = SetTowerSetpoints (FRONT, p_cmd, FALSE, 0);

      /* Flag param modified in 00xxSTATUS.  Is for old (Asterix) chemstation */
      /* This bit is set here and in Default setpts and cleared by the SETPTS */
      /* command.  New chemstations should use the CCPM parameter modified bit */
      /* This is done here so Bruce's code will see sampler setpts changed by */
      /* a method load or RUI (Pegasus) changes.                              */
      Inj_Status |= ALS_PARAM_MODIFIED;

      if (error != OK)
      CmdErrorHandler (p_cmd, 0, error);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoASTW                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoASTB - load/store back als tower workfile               */
/* ========                                                            */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* PARAMETERS: *p_cmd, *p_resp_parm - command system pointers          */
/*                                                                     */
/***********************************************************************/

INT16 DoASTB( CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   UI_ERR error;

   error = OK;

   /* this command requires at least 1 parameter */
   if (p_cmd->parmv[0] == 0)
   {
      CmdErrorHandler(p_cmd, 0, NUM_OF_PARAM);
      return NO_RESPONSE;
   }

   /* if '?' return tower setpts */
   if (p_cmd->parms[p_cmd->parmv[1]] == '?')
   {
      return AddTowerSetpts (BACK, p_resp_parm);
   }
   else
   /* load tower setpts     */
   {
      error = SetTowerSetpoints (BACK, p_cmd, FALSE, 0);

      /* Flag param modified in 00xxSTATUS.  Is for old (Asterix) chemstation */
      /* This bit is set here and in Default setpts and cleared by the SETPTS */
      /* command.  New chemstations should use the CCPM parameter modified bit */
      /* This is done here so Bruce's code will see sampler setpts changed by */
      /* a method load or RUI (Pegasus) changes.                              */
      Inj_Status |= ALS_PARAM_MODIFIED;

      if (error != OK)
      CmdErrorHandler (p_cmd, 0, error);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoASTB                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoASTR - load/store tray workfile                         */
/* ========                                                            */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* PARAMETERS: *p_cmd, *p_resp_parm - command system pointers          */
/*                                                                     */
/***********************************************************************/

INT16 DoASTR( CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   UI_ERR error;

   error = OK;

   /* this command requires at least 1 parameter */
   if (p_cmd->parmv[0] == 0)
   {
      CmdErrorHandler(p_cmd, 0, NUM_OF_PARAM);
      return NO_RESPONSE;
   }

   /* if '?' return tower setpts */
   if (p_cmd->parms[p_cmd->parmv[1]] == '?')
   {
      return AddTraySetpts (p_resp_parm);
   }
   else
   /* load tower setpts     */
   {
      error = SetTraySetpoints (p_cmd, FALSE, 0);

      /* Flag param modified in 00xxSTATUS.  Is for old (Asterix) chemstation */
      /* This bit is set here and in Default setpts and cleared by the SETPTS */
      /* command.  New chemstations should use the CCPM parameter modified bit */
      /* This is done here so Bruce's code will see sampler setpts changed by */
      /* a method load or RUI (Pegasus) changes.                              */
      Inj_Status |= ALS_PARAM_MODIFIED;

      if (error != OK)
      CmdErrorHandler (p_cmd, 0, error);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoASTR                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: ASOpcodes                                                 */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls routines needed to implement the AS commands.        */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 ASOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len)
{
INT16           parm_len;

   (void) max_resp_len;

   parm_len = NO_RESPONSE;

   switch( p_cmd->opcode.int_op )
   {
      case  MAKEINT('T', 'W'):
         parm_len = DoASTW(p_cmd,p_resp_parm);
         break;

      case  MAKEINT('T', 'B'):
         parm_len = DoASTB(p_cmd,p_resp_parm);
         break;

      case  MAKEINT('T', 'R'):
         parm_len = DoASTR(p_cmd,p_resp_parm);
         break;

      case MAKEINT( 'C', 'W' ):
         parm_len = DoCmd(p_cmd, p_resp_parm, &mASCW);
         break;

      case  MAKEINT('E','O'):
        parm_len = DoASEO(p_cmd,p_resp_parm);
        break;

      default:
         parm_len = NO_RESPONSE;
         CmdErrorHandler(p_cmd,0,INVALID_OP);
         break;
   }

   return parm_len;
}


/***********************************************************************/
/* END FUNCTION: ASOpcodes                                             */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: AS_Cmds                                                   */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls function which executes a command if one is          */
/*          available on the command queue.                            */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

void AS_Cmds(void)
{
   ExecCmds(&AS_Cmd_Q,ASOpcodes);
}

/***********************************************************************/
/* END FUNCTION: AS_Cmds                                               */
/***********************************************************************/
